﻿using System.Collections.Generic;
using System.Data;
using System;

namespace ZHDJ.MobileInterface
{
    public partial class GetPartyQuestionNaireInfo : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            PartyQuestionNaireInfoOutParam result = new PartyQuestionNaireInfoOutParam();
            PartyQuestionNaireInfoInParam param = new PartyQuestionNaireInfoInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as PartyQuestionNaireInfoInParam;

                if (string.IsNullOrEmpty(param.Survey_id))
                {
                    result.code = "0";
                    result.desc = "问卷ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    DataSet ds = InterfaceHelper.GetPartyQuestionNaireInfo(param.Survey_id);
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        PartyQuestionNaireInfo itemTemp;
                        PartyQuestionNaireOptionsInfo optionTemp;
                        //result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), 10000);
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new PartyQuestionNaireInfo();
                            itemTemp.Survey_id = dr["Survey_id"].ToString();
                            itemTemp.Title_Id = dr["Title_Id"].ToString();
                            itemTemp.oneOrMore = dr["oneOrMore"].ToString();
                            itemTemp.content = dr["content"].ToString();

                            DataSet dsOption = InterfaceHelper.GetQuestionNaireOption(itemTemp.Title_Id);
                            if (dsOption != null && dsOption.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr2 in dsOption.Tables[0].Rows)
                                {
                                    optionTemp = new PartyQuestionNaireOptionsInfo();
                                    optionTemp.option_content = dr2["OptionContent"].ToString();
                                    optionTemp.option_id = dr2["OptionID"].ToString();
                                    itemTemp.options.Add(optionTemp);
                                }
                            }


                            result.data.list.Add(itemTemp);
                        }
                    }
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetPartyQuestionNaireInfo", SerializeHelper.JsonSerializer<PartyQuestionNaireInfoInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<PartyQuestionNaireInfoInParam, PartyQuestionNaireInfoOutParam>();
            else
                SafeProcessRequest<PartyQuestionNaireInfoInParam, PartyQuestionNaireInfoOutParam>();
        }
    }

    #region 请求参数
    public class PartyQuestionNaireInfoInParam
    {
        /// <summary>
        /// 必填 调查ID
        /// </summary>
        public string Survey_id
        { get; set; }

    }
    #endregion

    #region 结果参数
    public class PartyQuestionNaireInfoOutParam
    {
        public PartyQuestionNaireInfoOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new PartyQuestionNaireInfoList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 列表
        /// </summary>
        public PartyQuestionNaireInfoList data
        { get; set; }
    }

    public class PartyQuestionNaireInfoList
    {
        public PartyQuestionNaireInfoList()
        {
            //total_pages = 0;
            list = new List<PartyQuestionNaireInfo>();
        }

        public List<PartyQuestionNaireInfo> list { get; set; }

        ///// <summary>
        ///// 总页数
        ///// </summary>
        //public int total_pages
        //{ get; set; }
    }

    /// <summary>
    /// 详情
    /// </summary>
    public class PartyQuestionNaireInfo
    {
        public PartyQuestionNaireInfo()
        {
            options = new List<PartyQuestionNaireOptionsInfo>();
        }
        /// <summary>
        /// 调查ID
        /// </summary>
        public string Survey_id
        { get; set; }

        /// <summary>
        /// 标题ID
        /// </summary>
        public string Title_Id
        { get; set; }

        /// <summary>
        /// 标题内容
        /// </summary>
        public string content
        { get; set; }

        /// <summary>
        /// 是否多选 0：单选；1：多选；
        /// </summary>
        public string oneOrMore
        { get; set; }

        /// <summary>
        /// 选项列表
        /// </summary>
        public List<PartyQuestionNaireOptionsInfo> options
        { get; set; }

    }

    public class PartyQuestionNaireOptionsInfo
    {
        /// <summary>
        /// 答题选项ID
        /// </summary>
        public string option_id
        { get; set; }

        /// <summary>
        /// 答题选项内容
        /// </summary>
        public string option_content
        { get; set; }
    }
    #endregion
}